package com.xpec.c4.service.module.datacenter.account;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xpec.c4.game.datamanager.DataRequestInfo;
import com.xpec.c4.game.datamanager.agent.AccountData;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.annotations.MessageType;
import com.xpec.c4.service.contexts.Contexts;
import com.xpec.c4.service.module.datacenter.DataCenterModule;


/**
 * 
 * @author yangbingyan
 *
 */
public class AccountDataProcess {

	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(AccountDataProcess.class);

	@MessageType(typeCode =  MessageTypes.CREATE_ACCOUNT_INFO)
	public void createAccountInfo(DataRequestInfo objInfo){
		AccountData info = (AccountData)objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		AccountDataManager result = ((DataCenterModule)Contexts.getModule()).getAccountDataManager();
		Object userdata = null;
		if(result != null){
			result.createDataNoCheck(info, srcModuleID, userdata);
		}
		
	}
	
	@MessageType(typeCode =  MessageTypes.QUERY_ACCOUNT_INFO)
	public void queryAccountInfo(DataRequestInfo objInfo){
		AccountData info = (AccountData)objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		AccountDataManager result = ((DataCenterModule)Contexts.getModule()).getAccountDataManager();
		Object userdata = null;
		if(result != null){
			result.readDataAsync(info, srcModuleID, userdata);
		}
		
	}
	
	@MessageType(typeCode = MessageTypes.UPDATE_ACCOUNT_INFO)
	public void updateAccountInfo(DataRequestInfo objInfo){
		AccountData info = (AccountData)objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		AccountDataManager result = ((DataCenterModule)Contexts.getModule()).getAccountDataManager();
		if(result != null){
			result.writeData(info, srcModuleID);
		}
	}

}
